<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<?php
session_start(); 

// 含入系統（資料庫）設定檔
require('config.inc.php');
require('db.php');

// 連結資料庫伺服器
db_connect();

// 選擇資料庫
db_select();

// 接收表單變數
$user = $_POST['txtUser'];
$pass = $_POST['txtPass'];

// 查詢帳號資料
// 建構 SQL 指令（查詢帳資料）
$sql = '';
$sql .= 'select count(*) as foundnum from Authentication where ';
$sql .= 'ID=\'' . $user . '\' and Password=\'' . $pass . '\';';

$result = mysql_query($sql) or die('Invalid query: ' . mysql_error());

$sql1 = '';
$sql1 .= 'select UserNo from Authentication where ';
$sql1 .= 'ID=\'' . $user  . '\';';
$result1 = mysql_query($sql1) or die('Invalid query: ' . mysql_error());
while ($row = mysql_fetch_assoc($result1)) {
    $UserNo=$row['UserNo'] ;
}

?>

<body>

<?php
$row = mysql_fetch_array($result);
$num = $row['foundnum'];
if ($num > 0) {
	
	 
	$_SESSION['ID'] = $user;
	$_SESSION['UserNo']=$UserNo;
	header("Location:"."main.php");
	
} else {
	echo '登入失敗!';
	
}
?>

<?php
// 清除查詢結果，釋放記憶空間
mysql_free_result($result);
mysql_free_result($UserNo);
?>

<?php
// 資料庫連結斷線
db_close();
?>

</body>
</html>
